package westh.ilib.struts.action.manage.conference;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.mule.extras.client.MuleClient;
import org.mule.umo.UMOMessage;
import org.apache.struts.action.Action;

import westh.ilib.bean.manage.ConferenceBean;
import westh.ilib.struts.action.manage.conference.ConferenceInfoAction;
import westh.util.YyAction;
import westh.config.Config;
public class ConferenceInfoAction extends Action{
	// 定义commons log
	private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
			.getLog(ConferenceInfoAction.class);
	//get clouds Ip address
	String localhostUrl = Config.get("localhostUrl");
	String remoteUrl = Config.get("remoteUrl");

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// 日志和权限检查，请勿删除
		westh.log.YyLog.addFootprint(request, "动作-显示资源详细信息");
		String conferenceId = request.getParameter("conferenceId");
		// 查询数据文件
		String dbName = "conference.dbxml";
		//将信息封装成json串
		JSONObject inJson = new JSONObject();
		inJson.put("conferenceId", conferenceId);
		inJson.put("dbName", dbName);
		String inputStr = inJson.toString();
		//json串传入相应的方法
		String outString = "";
		try {
			MuleClient clientD = new MuleClient();
			// 调用WebService
			UMOMessage umo = clientD.send("axis:http://"+localhostUrl+":4381/LIBJson/iDlibJson?method=getConferenceInfo",inputStr, null);
			outString = (String) umo.getPayload();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		//解析返回的json串
		JSONObject outJson = JSONObject.fromObject(outString);
		String retCode = outJson.getString("retCode");
		ConferenceBean conference = new ConferenceBean();
		//判断结果
		if (retCode.equals("0100")) {
			
			conference.setConferenceId(outJson.getString("conferenceId"));
			conference.setConferenceName(outJson.getString("conferenceName"));
			conference.setConferenceFullName(outJson.getString("conferenceFullName"));
			conference.setConferenceDateStart(outJson.getString("conferenceDateStart"));
			conference.setConferenceDateEnd(outJson.getString("conferenceDateEnd"));
			conference.setConferenceVenue(outJson.getString("conferenceVenue"));
			conference.setConferenceDeadline(outJson.getString("conferenceDeadline"));
			conference.setConferenceNotification(outJson.getString("conferenceNotification"));
			conference.setConferenceCameraReady(outJson.getString("conferenceCameraReady"));
			conference.setConferenceDateReg(outJson.getString("conferenceDateReg"));
			conference.setConferenceUrl(outJson.getString("conferenceUrl"));
			
			request.setAttribute("conference", conference);
			return mapping.findForward("succ");
		} else {
			String insertSubjectIndustry = "查看失败";
			request.setAttribute("info", insertSubjectIndustry);
			request.setAttribute("redirect", "../conferenceListPre.do");
			return mapping.findForward("fail");
		}
	}

}
